package org.huangrui.spark.scala.core.rdd.operate

import org.apache.spark.{SparkConf, SparkContext}

/**
 * 默认情况下，新创建的RDD的分区数量和之前旧的RDD的数量保持一致
 * 默认情况下，数据流转所在的分区编号不变，除非重新分区
 * @Author hr
 * @Create 2024-10-16 19:25
 */
object Spark02_Operate_Transform_Map_1 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("spark")
    val sc = new SparkContext(conf)
    val nums = List(1, 2, 3, 4, 5, 6)
    val rdd = sc.parallelize(nums, 2)
    val newRdd = rdd.map((x: Int) => x * 2)

    rdd.saveAsTextFile("output1")
    newRdd.saveAsTextFile("output2")
    sc.stop()
  }
}
